

import pygame
from Base import Base
from random import *

class Ememy(Base):

    def __init__(self,bg_size,img,speed,minTop,maxTop,over_img,lives=1,hit_img=""):

        # 继承类
        Base.__init__(self,img,over_img,bg_size)

        self.speed=speed
        self.maxTop=maxTop
        self.minTop=minTop

        self.lives = lives

        # ranint 需要两个参数，生成这两个参数的范围值
        self.reset()

        if hit_img:
            self.hit_img = pygame.image.load("images/"+hit_img+".png").convert_alpha()
            self.is_hit=False

    def move(self):

        ememyRect = self.rect 

        if ememyRect.top<self.bgH:
            ememyRect.top += self.speed
        
        else:
            self.reset()

    def reset(self):
        ememyRect = self.rect 

        self.actived=True
        self.currentLive = self.lives
        # print("minTop*ememyRect.height",self.minTop*ememyRect.height)
        # ememyRect.left,ememyRect.top = randint(0,self.bgW - ememyRect.width),randint(-5*ememyRect.height,0)

        ememyRect.left,ememyRect.top = randint(0,self.bgW - ememyRect.width),randint(self.minTop*self.bgH,self.maxTop*self.bgH)


class SmallEmemy(Ememy):

    def __init__(self,bg_size):

        Ememy.__init__(self,bg_size,"enemy1",2,-5,0,
            ["enemy1_down1","enemy1_down2","enemy1_down3","enemy1_down4",]
        )

    
class MediumEmemy(Ememy):

    def __init__(self,bg_size):

        Ememy.__init__(self,bg_size,"enemy2",1,-5,-2,
            ["enemy2_down1","enemy2_down2","enemy2_down3","enemy2_down4",]
        ,5,"enemy2_hit")


class LargeEmemy(Ememy):

    def __init__(self,bg_size):

        Ememy.__init__(self,bg_size,"enemy3_n1",1,-15,-5,
            ["enemy3_down1","enemy3_down2","enemy3_down3","enemy3_down4","enemy3_down5","enemy3_down6",]
        ,15,"enemy3_hit")
        
        self.image2 = pygame.image.load("images/enemy3_n2.png").convert_alpha()
